//
//  SDHSportsWinRateView.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/8.
//

#import "SDHSportsWinRateView.h"

const static CGFloat kRateViewWidth = 100;

@interface SDHSportsWinRateView ()

@property (nonatomic, strong) UILabel *leftLb;
@property (nonatomic, strong) UILabel *gapLb;
@property (nonatomic, strong) UILabel *rightLb;

@end

@implementation SDHSportsWinRateView

- (id)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor yellowColor];
        UILabel *leftLabel = [UILabel new];
        leftLabel.backgroundColor = leftTeamTitleColor;
        [self addSubview:leftLabel];
        self.leftLb = leftLabel;
        
        UILabel *gapLabel = [UILabel new];
        gapLabel.backgroundColor = [UIColor grayColor];
        [self addSubview:gapLabel];
        self.gapLb = gapLabel;
        
        UILabel *rightLabel = [UILabel new];
        rightLabel.backgroundColor = rightTeamTitleColor;
        [self addSubview:rightLabel];
        self.rightLb = rightLabel;
        
        __weak typeof(self) weakSelf = self;
        [leftLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf);
            make.left.equalTo(weakSelf);
            make.right.equalTo(gapLabel.mas_left);
            make.bottom.equalTo(weakSelf);
            make.width.equalTo(@(kRateViewWidth/2));
            make.height.equalTo(weakSelf);
        }];
        
        [gapLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf);
            make.left.equalTo(leftLabel.mas_right);
//            make.right.equalTo(rightLabel.mas_left);
            make.bottom.equalTo(weakSelf);
//            make.width.equalTo(@(2));
            make.height.equalTo(weakSelf);
        }];
        
        [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf);
            make.left.equalTo(gapLabel.mas_right);
            make.right.equalTo(weakSelf);
            make.bottom.equalTo(weakSelf);
            make.height.equalTo(weakSelf);
        }];
        
        [self mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(kRateViewWidth));
        }];
    }
    
    return self;
}

- (void)updateLeft:(CGFloat)left right:(CGFloat)right {
    [self.leftLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(left / 100 * self.width));
    }];
    [self.rightLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(right / 100 * self.width));
    }];
}

@end
